package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.BookDao;
import dao.UserDao;
import dao.factory.DaoFactory;
import pojo.Book;
import pojo.User;

/**
 * Servlet implementation class ErrorServlet
 */
@WebServlet("/error")
public class ErrorServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ErrorServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String info = request.getParameter("info");
		if (info!=null) {
			request.setAttribute("info", info);
		}else{
			request.setAttribute("info", "error happen");
		}
		request.getRequestDispatcher("error.jsp").forward(request, response);
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		User user = new User(null,"allen","123");
//		UserDao userDao = DaoFactory.getInstance();
//		userDao.add(user);
		
//		Book book1 = new Book(null,"java 编程思想","http://localhost:8080/image/1.jpg",102); 
		Book book2 = new Book(null,"Head first 设计模式","http://localhost:8080/image/2.jpg",85); 
		Book book3 = new Book(null,"重构，改善现有代码的设计","http://localhost:8080/image/3.jpg",96); 
		BookDao bookDao = DaoFactory.getBookDaoInstance();
//		bookDao.add(book1);
		bookDao.add(book2);
		bookDao.add(book3);
	}

}
